#include "Projectile3D.h"
#include "GlobalDefines.h"

EnergyBall::EnergyBall() : m_scale(10.0f)
{
	m_sphereMesh = NULL;
}

EnergyBall::~EnergyBall()
{
	
}

void EnergyBall::updateBall(float a_time)
{
	m_time = a_time;

	setBallOld();

	initEnrgyBall();

    createEnrgyBall();

    drawBall();
}

void EnergyBall::setBallPos(D3DXVECTOR3 a_playerPos, float a_scale)
{
	m_scale = 0.0f;
    m_ballPos.x = a_playerPos.x;
	m_ballPos.z = a_playerPos.z;
	m_scale = a_scale;
}

void EnergyBall::setBallRot(D3DXVECTOR3 a_playerRot)
{
	m_ballRot.x = a_playerRot.x;
	m_ballRot.y = a_playerRot.y;
	m_ballRot.z = a_playerRot.z;
}

void EnergyBall::setNukeScale(float a_scale)
{
	m_scale = a_scale;
}

void EnergyBall::initEnrgyBall()
{
	// Sphere
	float sphereRadius = m_scale;
	int numSlices = 12;
	int numStacks = 12;
	// create a sphere using the d3dx util library
	D3DXCreateSphere(dxMgr.getDevice(), 
					 sphereRadius, 
					 numSlices, 
					 numStacks, 
					 &m_sphereMesh, 
					 NULL);

	m_scale = sphereRadius;
}

void EnergyBall::createEnrgyBall()
{
    m_ballPos.y = 20.0f;
	
    m_ballPos.x += framex * sin(D3DXToRadian(m_ballRot.z)) * m_time;
    m_ballPos.z += framez * cos(D3DXToRadian(m_ballRot.z)) * m_time;

    D3DXMATRIX matShip, matScale, matTranslate, matTrans;
        
    // set the scaling
    D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

    // set the translation
    D3DXMatrixTranslation(&matTranslate, m_ballPos.x, m_ballPos.y, m_ballPos.z);

    // mulitple the translation matrices
    D3DXMatrixMultiply(&matShip, &matScale, &matTranslate);
                        
    // transform the object in world space
    dxMgr.getDevice()->SetTransform(D3DTS_WORLD, &matShip);
}

void EnergyBall::drawBall()
{
	dxMgr.getDevice()->SetMaterial(&m_mtrl);
	m_sphereMesh->DrawSubset(0);
}

void EnergyBall::colorBall()
{
	
}

D3DXVECTOR3 EnergyBall::getBallPos()
{
	m_ballPos.y = 0.0f;

	return m_ballPos;
}

float EnergyBall::getBallRad()
{
	return m_scale;
}

D3DXVECTOR3 EnergyBall::getNukePos()
{
	m_ballPos.y = 0.0f;

	return m_ballPos;
}

float EnergyBall::getNukeRad()
{
	return m_scale;
}

void EnergyBall::destroyEnrgyBall()
{
	if(m_sphereMesh != NULL)
	{
		m_sphereMesh->Release();
		m_sphereMesh = NULL;
	}
}

